import React, { useEffect, useState } from 'react'
import { inquire } from '../services/commodity'
import List from '../components/commodity/List'
import Add from '../components/commodity/Add'
import Updata from '../components/commodity/Updata'
import Search from '../components/commodity/Search'
import { Col, Row } from 'antd';
export default function Commodity() {
  let [commodity, setCommodity] = useState([])
  let [search, setASearch] = useState({})//保存搜索对象
    let [pagination, setPagination] = useState({//分页
        position: ["bottomCenter"],
        showSizeChanger: true,
        pageSizeOptions: [5, 10, 20],
        showTotal: (total) => `总共${total}条`,
        showQuickJumper: true
    })
    const show = async (obj) => {
        if (obj) {
            obj = { ...search, ...obj }
            setASearch(obj)
        } else {
            obj = search
        }
        let {data} = await inquire({ ...obj });
        console.log("data",data);
        setCommodity(data.rows)
        setPagination({ ...pagination, total: data.total, pageSize: data.pageSize,current:parseInt(data.current) })
    }
  useEffect(() => {
    show()
  },[commodity.length])

  return (
    <div>
      <Row>
      <Col span={2}>
      <Add show={show}></Add>
    </Col>
    <Col span={18} >
    <Search show={show}></Search>
    </Col>
      </Row>
      <List show={show} commodity={commodity}  pagination={pagination}></List>
      <Updata show={show}></Updata>
    </div>
  )
}
